package csc.daonjpa.java.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Component;

import csc.daonjpa.java.controller.EntityManagerFactoryUtil;
import csc.daonjpa.java.domain.BaseInfo;
import csc.daonjpa.java.domain.Customer;
import csc.daonjpa.java.domain.TargetAccount;
import csc.daonjpa.java.transaction.TransactionManager;

@Component
public class TargetDAO {
	
	
	
	public List<TargetAccount> getTargetAccounts() {
		EntityManager em = TransactionManager.getEntityManager();
		TypedQuery<TargetAccount> query = em.createQuery("SELECT a FROM TargetAccount a", TargetAccount.class);
		List<TargetAccount> targetAccounts = null;
		targetAccounts = query.getResultList();
		return targetAccounts;
	}
	
	public TargetAccount getTargetAccount (String accountNum) {
		EntityManager em = TransactionManager.getEntityManager();
		TypedQuery<TargetAccount> query = em.createQuery("SELECT c FROM TargetAccount c WHERE c.accountNumber = :id", TargetAccount.class);
		TargetAccount targetAccount = query.setParameter("id", accountNum).getSingleResult();
		return targetAccount;
	}
	
}
